home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr50 / picalc06.zip / PICALC.DOC < prev    next >
Text File  |  1993-06-08  |  4KB  |  106 lines

  1. Program   : PICALC
  2. Version   : 0.5
  3.  
  4.  
  5. Function  : Computes the value of PI from QuickBasic's Random Number
  6.             Generator.
  7.  
  8.  
  9. Usage     : From the DOS Prompt, enter "PICALC".
  10.             There are no command line options, Program in entirely menu
  11.             driven.
  12.  
  13.  
  14. MainMenu  : Allows the user to enter the options for the run,
  15.             Such as: Whether Automatic Samples are to be taken and if so
  16.                      by what technique.
  17.                      If Automatic Samples are to be taken - at what frequency.
  18.              If Samples are to be taken to the printer as well as to
  19.                      the screen.
  20.         NOTE: The main menu is altered dynamically depending on what
  21.                   options are chosen (ex: If no samples are to be taken,
  22.                   the items relating to frequency and printer trace are
  23.                   omitted.
  24.             Each selection from the main menu leads to a data input screen
  25.             for that selection. On completion of the data input, the program
  26.         then re-presents the main menu with the updated options.
  27.  
  28.  
  29. RunTime   : During the computation run, the user has the option of taking a
  30.             sample on demand (to the screen only), or taking a final sample
  31.         and terminating the run.
  32.  
  33.  
  34. EndingRun : The program will loop through the main compute loop for 
  35.             2,147,483,647 iterations or until the user gets sick of it and
  36.         hits the <ESCAPE> key to terminate it.
  37.             (On a 286 at 12.5 megahertz, the maximum iterations would take
  38.             somewhere around 75 days).
  39.  
  40.  
  41. How?      : Consider a circle with a radius of 1 unit centered on the origin
  42.         in the X-Y plane.
  43.         Now lets consider a square 2 units on a side around the circle.
  44.  
  45.         We know the area of the square is 4 square units, and the area
  46.             of the circle is PI*R^2, or in this case PI since R = 1.
  47.             We also know that the equation for a circle centered at the
  48.             origin is R^2 = X^2 + Y^2, and also that the distance from the
  49.         origin to the circle itself is R = (X^2 + Y^2)^0.5.
  50.  
  51.             Now to simplify things lets cut our figure into quarters and
  52.         only look at one of the quarters. We have a unit square with
  53.             an area of 1 square unit with a quarter circle in it with an
  54.             area of PI/4.
  55.  
  56.             OK? - Now to the Random stuff.
  57.             We take our figure and
  58.                Pin it on the wall and throw darts at it, or
  59.                Lay it out in the backyard and let the rain fall on it, or
  60.                Fence off a square mile of meadowland and let my cow
  61.               (Pythagoras) drop cowpies on it, or
  62.                Generate X and Y values for a point on the figure.
  63.  
  64.             When we finish, some of the items will be within the arc of the
  65.         circle, and some outside of it.
  66.         And all we have to do is count the number of items that fell
  67.         within the arc, divide this figure by the total number of items,
  68.             and multiply by 4 to get the value of PI.
  69.  
  70.             Using Random Numbers, if the computed R is less than 1 then it is
  71.             within the arc. If greater than 1 then it is outside. Otherwise
  72.         we will toss a coin to see where to count it.
  73.  
  74.  
  75. Why???    : Because it is do'able, and it gives the computer something to do
  76.             while it is resting.
  77.  
  78.  
  79. Notes     : Do NOT expect repeatable results. The random number generator is
  80.             primed by the value in the system timer.
  81.  
  82.             Since Random Numbers are used in the computations, the program
  83.             does NOT converge to a value. (Wanders all over hell, but slowly
  84.             refines the value of PI).
  85.  
  86.             Rather underwhelmed by QuickBasic's Random Number Generator, only
  87.             single precision numbers. PICALC 'fuzzes' them on conversions to
  88.             double precision. At a later date, I may incorporate my own 
  89.             generator.
  90.  
  91.             Program was first written about 1963 on an IBM-1620. Has been
  92.             through many machines and languages since then.
  93.  
  94.  
  95. By        : Tom Taylor
  96.             50 Bret Ave
  97.             San Rafael, CA 94901
  98.             Ph (415) 457-1071
  99.  
  100.             
  101.  
  102.  
  103.  
  104.  
  105.             
  106.